﻿/*************************************************************************
 * Created by OhZee Creative, LLC
 * 2013
 * This code is licensed under Microsoft Public License (Ms-PL)
 * http://opensource.org/licenses/ms-pl
 * http://ozframework.codeplex.com/
 *************************************************************************/

namespace OhZeeCreative.Windows8
{
    using Windows.System.Display;

    public class KeepAlive
    {
        public bool IsAlive { get; private set; }
        private DisplayRequest DisplayRequest;

        public KeepAlive(bool turnOn = false)
        {
            DisplayRequest = new DisplayRequest();
            if (turnOn)
            {
                this.On();
            }
        }

        public void On()
        {
            if (!IsAlive)
            {
                DisplayRequest.RequestActive();
                IsAlive = true;
            }
        }

        public void Off()
        {
            if (IsAlive)
            {
                DisplayRequest.RequestRelease();
                IsAlive = false;
            }
        }

        public bool Toggle(bool onOrOff)
        {
            if (onOrOff)
            {
                On();
            }
            else
            {
                Off();
            }

            return IsAlive;
        }

    }
}
